// scaup - Scala up!
// (c) 2008-2009, Normen Müller, normen.mueller@gmail.com  
// $Id: DM.scala 2476 2009-10-05 16:54:16Z nmueller $
package locutor.model.parsing.dm

import java.io.File
import java.text.MessageFormat.{format}

import scaup.Views._

/** 
 * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 * @version 0.0.2 */
case class DMError(message: String) extends Exception(message)

/** This object provides a simple interface to the DM parser class.
 * 
 * @author <a href="mailto:normen.mueller@googlemail.com">Normen M&#xFC;ller</a>
 * @version 0.0.2 */
object DM extends Parser {
//  def apply(input: File) =
//    if(input == null || !(input exists))
//      throw new DMError(format("Physical DM file may not be null (''{0}'').", input))
//    else apply(input.content)
  
  def apply(input: String) =
    if(input == null)
      throw new DMError("Physical DM representation may not be null.")
    else parse(input)
  
  def parse(input: String) = phrase(dm)(new lexical.Scanner(input)) match {
    case Success(result, _) => result
    case n@_                => throw new DMError(format("DM parsing error in\n{0}\n\n", input) + n)
  }
}
